<?php
/*
Plugin Name: AdultATOM
Plugin URI: http://code.google.com/p/adultatom4wordpress/
Description: This code implements the AdultATOM protocol (a set of Atom usage principals) described here for WordPress.
Author: Mr-Yellow
Version: 1.0.19
Author URI: mailto:mr-yellow@mr-yellow.com
*/

 
// http://code.google.com/p/phpatomlib/
require_once('atomlib.php');

// Allocate all necessary memory for the image.
ini_set('memory_limit', '-1');

add_action('admin_menu', 'adultatom_options');

function adultatom_options() {
	add_management_page('AdultATOM Updating', 'AdultATOM Update', 8, 'adultatom', 'parse');
	add_options_page('AdultATOM', 'AdultATOM', 8, 'adultatom', 'options_page');
}

add_action('wp_head', 'adultatom_css');
add_action('admin_head', 'adultatom_css');

function adultatom_css() {
	echo '<script type="text/javascript" src="/flash/swfobject.js"></script>';
	echo "\n<style type='text/css'>\n";
	echo get_option('adultatom_css');
	echo "\n</style>\n";
}



function parse() {
	global $wpdb;
	
	$cr = "\n";
	$feeds = get_option('adultatom_feeds');
    $thumb_height = get_option('adultatom_thumb_height');
    $thumb_width = get_option('adultatom_thumb_width');
    $flash_height = get_option('adultatom_flash_height');
    $flash_width = get_option('adultatom_flash_width');    
    $thumb_dir = get_option('adultatom_thumb_dir');
    $thumb_url = get_option('adultatom_thumb_url');
    $otherlinks = get_option('adultatom_otherlinks');
    
	$save_to_file = 1;
	$image_quality = 100;
	$image_type = 2;
	
	foreach ($feeds as $feedurl) {	
		if ($feedurl!='') {
			echo "##########################<BR/>\n";
			echo "<b>Feed: ".$feedurl."</b><BR/>\n";	
			$parser = new AtomParser();
			$parser->debug = false;
			$parser->FILE = $feedurl;
			if(!$parser->parse()) {
				throw new Exception($parser->error);
			} else {
				$contents = Array();
				$contents = $parser->feed;
				
				foreach ($contents->entries as $entry) {
					$flvthumb_url = array();
					$flv_url = array();
					$flv_length = array();
					$flv_title = array();
					
					$mpgthumb_url = array();
					$mpg_url = array();
					$mpg_length = array();
					$mpg_title = array();
					
					$other_url = array();
					$other_title = array();
					
					$flv_cnt = 0;
					$mpg_cnt = 0;
					$other_cnt = 0;
					
					$twotwofiveseven_url = '';
					$sponsor_url = '';
					$sponsor_title = '';
					$buy_title = '';
					$buy_image = '';
					$buy_url = '';
			
					$video_id = md5($entry->id);
					$title = $entry->title[1];
					$description = $entry->content[1];
			
					foreach ($entry->links as $link) {
						
						// 2257
						if ($link['title'] == "2257") {
							$twotwofiveseven_url = $link['href'];
							
						// MPEGs
						} else if ($link['type'] == "video/mpeg" && $link['rel']=="enclosure") {
							$mpg_length[$mpg_cnt] = $link['length'];
							$mpg_length[$mpg_cnt] = sec2time($mpg_length[$mpg_cnt]);
							if ($mpg_length[$mpg_cnt]["minutes"]>0) {
								$mpg_length[$mpg_cnt] = $mpg_length[$mpg_cnt]["minutes"]."m ".$mpg_length[$mpg_cnt]["seconds"]."s";
							} else {
								$mpg_length[$mpg_cnt] = $mpg_length[$mpg_cnt]["seconds"]."s";
							}
							$mpg_url[$mpg_cnt] = $link['href'];
							$mpg_title[$mpg_cnt] = $link['title'];
							$mpgthumb_url[$x] = '';
							$mpg_cnt++;
							
						// FLVs
						} else if ($link['type'] == "video/x-flv" && $link['rel']=="enclosure") {
							$flv_length[$flv_cnt] = $link['length'];
							$flv_length[$flv_cnt] = sec2time($flv_length[$flv_cnt]);
							if ($flv_length[$flv_cnt]["minutes"]>0) {
								$flv_length[$flv_cnt] = $flv_length[$flv_cnt]["minutes"]."m ".$flv_length[$flv_cnt]["seconds"]."s";
							} else {
								$flv_length[$flv_cnt] = $flv_length[$flv_cnt]["seconds"]."s";
							}
							$flv_url[$flv_cnt] = $link['href'];
							$flv_title[$flv_cnt] = $link['title'];
							$flvthumb_url[$x] = '';
							$flv_cnt++;
							
						// Sponsor Link
						} else if ($link['type'] == "text/html" && $link['rel']=="alternate") {
							$sponsor_url = $link['href'];
							$sponsor_title = $link['title'];
							
						// Buy DVD Link
						} else if (preg_match('/Buy DVD/i',$link['title']) && $buy_url=='' && $link['type'] == "text/html" && $link['rel']=="related") {
							$buy_title = $link['title'];
							$buy_url = $link['href'];
							
						// Other Links
						} else {
							if (substr($link['title'], 0, 5) != 'image') {
								$other_url[$other_cnt] = $link['href'];
								$other_title[$other_cnt] = $link['title'];
								$other_cnt++;
							}
						}
					}
					
					// Match Images to Links
					foreach ($entry->links as $link) {
						for ($x=0;$x<$flv_cnt;$x++) {		
							if ('image['.$flv_title[$x].']' == $link['title'] && $link['type'] == "image/jpeg" && $link['rel']=="related") {
								$flvthumb_url[$x] = $link['href'];
							}
						}
						for ($x=0;$x<$mpg_cnt;$x++) {
							if ('image['.$mpg_title[$x].']' == $link['title'] && $link['type'] == "image/jpeg" && $link['rel']=="related") {
								$mpgthumb_url[$x] = $link['href'];
							}
						}
						if ('image['.$buy_title.']' == $link['title'] && $link['type'] == "image/jpeg" && $link['rel']=="related") {
							$buy_image = $link['href'];
						}
					}
					
					if ($title!='') {
						$date_uploaded = date('Y-m-d H:i:s',strtotime($entry->published));
						
						echo "<HR><BR/><BR/>\n\n";
						echo "<b>video_id:</b> " . $video_id . "<BR/>\n";
						echo "<b>title:</b> " . $title . "<BR/>\n";
						echo "<b>description:</b> " . $description . "<BR/>\n";
						echo "<b>date_uploaded:</b> " . $date_uploaded . "<BR/>\n";
						echo "<b>2257:</b> " . $twotwofiveseven_url . "<BR/>\n";
						echo "<b>sponsor_title:</b> " . $sponsor_title . "<BR/>\n";
						echo "<b>sponsor_url:</b> " . $sponsor_url . "<BR/>\n";
						echo "<b>buy_title:</b> " . $buy_title . "<BR/>\n";
						echo "<b>buy_url:</b> " . $buy_url . "<BR/>\n";
						
						$content = $description;						
						
						$bShowlegal = false;						
						if (count($flv_title)>0) {
							echo "<BR/><b>FLVs</b><BR/>\n";
							for ($x=0;$x<count($flv_title);$x++) {		
								echo "<b>Title:</b> " . $flv_title[$x] . "<BR/>\n";
								echo "<b>Thumb:</b> " . $flvthumb_url[$x] . "<BR/>\n";
								echo "<b>URL:</b> " . $flv_url[$x] . "<BR/>\n";
								echo "<b>Length:</b> " . $flv_length[$x] . "<BR/>\n";
								
								$content .= '<DIV CLASS="adultatom_flv_wrap" id="flvplayer_'.$video_id.'_'.$x.'"></DIV>'.$cr;
								$content .= '<DIV CLASS="adultatom_flv_text">';
								$content .= $flv_title[$x] . '&nbsp;&nbsp;['. $flv_length[$x] .']';
								$content .= '</DIV>'.$cr;
								$content .= '<script type="text/javascript">'.$cr;
								$content .= 'var so = new SWFObject("/flash/flvplayer.swf", "flvplayer_'.$video_id.'_'.$x.'", "'.$flash_width.'", "'.$flash_height.'", "8", "#FFFFFF");'.$cr;
								//$content .= 'so.useExpressInstall("/flash/expressinstall.swf");'.$cr;
								$content .= 'so.addVariable("logo", "/images/playerlogo.png");'.$cr;
								$content .= 'so.addVariable("file", "'.$flv_url[$x].'");'.$cr;
								$content .= 'so.addVariable("image", "'.$flvthumb_url[$x].'");'.$cr;
								$content .= 'so.addVariable("showfsbutton", false);'.$cr;
								$content .= 'so.addVariable("displayheight", '.$flash_height.');'.$cr;
								$content .= 'so.addVariable("displaywidth", '.$flash_width.');'.$cr;
								$content .= 'so.addVariable("height", '.$flash_height.');'.$cr;
								$content .= 'so.addVariable("width", '.$flash_width.');'.$cr;
								$content .= 'so.addVariable("link", "'.$sponsor_url.'");'.$cr;
								$content .= 'so.addVariable("linktarget", "_blank");'.$cr;
								$content .= 'so.addVariable("backcolor", "0xFFFFFF");'.$cr;
								$content .= 'so.write("flvplayer_'.$video_id.'_'.$x.'");'.$cr;
								$content .= '</script>'.$cr;
								
							}
							$bShowlegal=true;
						}
						
						if (count($mpg_title)>0){ 
							//$content .= '<BR/>';
							$content .= '<DIV CLASS="adultatom_mpeg_wrap">';
							echo "<BR/><b>MPEGs</b><BR/>\n";
							for ($x=0;$x<count($mpg_title);$x++) {		
								echo "<b>Title:</b> " . $mpg_title[$x] . "<BR/>\n";
								echo "<b>Thumb:</b> " . $mpgthumb_url[$x] . "<BR/>\n";
								echo "<b>URL:</b> " . $mpg_url[$x] . "<BR/>\n";
								echo "<b>Length:</b> " . $mpg_length[$x] . "<BR/>\n";
								if ($mpgthumb_url[$x]!='') {
									GenerateThumbFile($mpgthumb_url[$x], $thumb_dir.$video_id.'_'.$x.'.jpg', $thumb_width, $thumb_height, $save_to_file, $image_type, $image_quality);
								}
								$content .= '<A CLASS="adultatom_mpeg" ID="mpeg_'.$video_id.'" NAME="mpeg_'.$video_id.'" HREF="'.$mpg_url[$x].'" TITLE="'.$mpg_title[$x].'"><IMG SRC="'.$thumb_url.$video_id.'_'.$x.'.jpg" TITLE="'.$mpg_title[$x].'" ALT="'.$mpg_title[$x].'" BORDER=0><BR/>';
								$content .= $mpg_title[$x] . '&nbsp;&nbsp;['. $mpg_length[$x] .']';
								$content .= '</A>';
							}
							$content .= "</DIV>";
							$bShowlegal=true;
						}
						
						$content .= '<DIV CLASS="adultatom_link_wrap">';
						if ($buy_url!='') {
							$content .= '<A CLASS="adultatom_link" HREF="'.$buy_url.'" TITLE="'.$buy_title.'">';
							if ($buy_image!='') {
								$content .= '<IMG SRC="'.$buy_image.'" BORDER=0><BR/>';
							}
							$content .= $buy_title.' - ' . $title . '</A><BR/>';
						}
						if ($sponsor_url!='') {
							$content .= '<A CLASS="adultatom_link" HREF="'.$sponsor_url.'" TITLE="'.$sponsor_title.'">More from: '.$sponsor_title.'</A><BR/>';
						}
						
						if ($otherlinks==1) {
							echo "<BR/><b>Others</b><BR/>\n";
							for ($x=0;$x<count($other_title);$x++) {		
								echo "<b>Title:</b> " . $other_title[$x] . "<BR/>\n";
								echo "<b>URL:</b> " . $other_url[$x] . "<BR/>\n";
								$content .= '<A CLASS="adultatom_other" ID="other_'.$video_id.'" NAME="other_'.$video_id.'" HREF="'.$other_url[$x].'" TITLE="'.$mpg_title[$x].'">'.$other_title[$x].'</A><BR/>';
							}
						}						
						$content .= "</DIV>";
						if ($twotwofiveseven_url!='' && $bShowlegal) {
							$content .= '<BR/><DIV><A CLASS="adultatom_twotwofiveseven" HREF="'.$twotwofiveseven_url.'" TITLE="Title 18 &sect; 2257">Title 18 &sect; 2257</A></DIV>';
							//$content .= "<BR/>\n ";
						}
					
						echo "<BR/>\n<b>content:</b> <BR/>\n<BR/>\n" . preg_replace('/\n/i','',$content) . "<BR/>\n ";
						
						$post_name = sanitize_title($title);
						/*
						$post_name = preg_replace('/\s/i','-',strtolower(stripslashes($post_name)));
						$post_name = preg_replace('/([^a-z,-])/i','',$post_name);
						while (preg_match('/--/i',$post_name)) {
							$post_name = preg_replace('/--/i','-',$post_name);
						}
						*/
						
						$post_author = get_option('adultatom_post_author');
    					$post_category = get_option('adultatom_post_category');
    					$post_author = get_option('adultatom_post_author');
						$post_date = $date_uploaded;
						$post_date_gmt = $date_uploaded;
						$post_content = $content;
						$post_title = $title;
						$post_category = get_option('adultatom_post_category');
						$post_excerpt = '';
						$post_status = 'publish';
						$comment_status = 'open';
						$ping_status = 'open';
						$post_password = '';
						$to_ping = '';
						$pinged = '';
						$post_modified = $date_uploaded;
						$post_modified_gmt = $date_uploaded;
						$post_content_filtered = '';
						$post_parent = 0;						
						$menu_order = 0;
						$post_type = 'post';
						$post_mime_type = '';
						$comment_count = 0;
						
						$post_name_check = '';
						$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' LIMIT 1");						
						echo "<b>dupe_check:</b> " . $post_name_check . "<BR/>\n";
						if ($post_name_check=='') {
							$sql = "INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, post_type, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type, guid) VALUES ('$post_author', '$post_date', '$post_date_gmt', '".mysql_real_escape_string($post_content)."', '$post_content_filtered', '".mysql_real_escape_string($post_title)."', '$post_excerpt', '$post_status', '$post_type', '$comment_status', '$ping_status', '$post_password', '$post_name', '$to_ping', '$pinged', '$post_date', '$post_date_gmt', '$post_parent', '$menu_order', '$post_mime_type', '$guid');";
							$res = $wpdb->query($sql);
							if ($res) {
								$post_ID = (int) $wpdb->insert_id;
								$wpdb->query("UPDATE $wpdb->posts SET guid = '" . get_permalink($post_ID) . "' WHERE ID = '$post_ID'");
								echo "<b>Result:</b> Success<BR/>\n";
							} else {
								echo "<b>Result:</b> Failed<BR/>\n";
							}
						} else {
							echo "<b>Result:</b> Skipped<BR/>\n";
						}
					}
				}
			}
		}
	}
}


function options_page() {
    $adultatom_feeds = get_option('adultatom_feeds');
    $adultatom_thumb_height = get_option('adultatom_thumb_height');
    $adultatom_thumb_width = get_option('adultatom_thumb_width');    
    $adultatom_thumb_dir = get_option('adultatom_thumb_dir');
    $adultatom_thumb_url = get_option('adultatom_thumb_url');
    $adultatom_post_author = get_option('adultatom_post_author');
    $adultatom_post_category = get_option('adultatom_post_category');
    $adultatom_css = get_option('adultatom_css');
    $adultatom_flash_height = get_option('adultatom_flash_height');
    $adultatom_flash_width = get_option('adultatom_flash_width');
    $adultatom_otherlinks = get_option('adultatom_otherlinks');
    
    
    if( $_POST['mt_submit_hidden'] == 'Y' ) {
        
	    $adultatom_feeds = $_POST['adultatom_feeds'];
	    $adultatom_thumb_height = $_POST['adultatom_thumb_height'];
	    $adultatom_thumb_width = $_POST['adultatom_thumb_width'];
	    $adultatom_thumb_dir = $_POST['adultatom_thumb_dir'];
	    $adultatom_thumb_url = $_POST['adultatom_thumb_url'];
	    $adultatom_post_author = $_POST['adultatom_post_author'];
	    $adultatom_post_category = $_POST['adultatom_post_category'];
	    $adultatom_css = $_POST['adultatom_css'];
	    $adultatom_flash_height = $_POST['adultatom_flash_height'];
	    $adultatom_flash_width = $_POST['adultatom_flash_width'];
	    $adultatom_otherlinks = $_POST['adultatom_otherlinks'];
	    
        
        update_option('adultatom_feeds', $adultatom_feeds);
        update_option('adultatom_thumb_height', $adultatom_thumb_height);
        update_option('adultatom_thumb_width', $adultatom_thumb_width);
        update_option('adultatom_thumb_dir', $adultatom_thumb_dir);
        update_option('adultatom_thumb_url', $adultatom_thumb_url);
        update_option('adultatom_post_author', $adultatom_post_author);
        update_option('adultatom_post_category', $adultatom_post_category);
        update_option('adultatom_css', $adultatom_css);
        update_option('adultatom_flash_height', $adultatom_flash_height);
        update_option('adultatom_flash_width', $adultatom_flash_width);
        update_option('adultatom_otherlinks', $adultatom_otherlinks);
		?>
		<div class="updated"><p><strong><?php _e('Options saved.', 'mt_trans_domain' ); ?></strong></p></div>
		<?
    } else {
	    
	    if (!($adultatom_thumb_height>0)) {
		    $adultatom_thumb_height = 125;
	    }
	    if (!($adultatom_thumb_width>0)) {
		    $adultatom_thumb_width = 167;
	    }
	    if (!($adultatom_flash_height>0)) {
		    $adultatom_flash_height = 240;
	    }
	    if (!($adultatom_flash_width>0)) {
		    $adultatom_flash_width = 320;
	    }
	    if ($adultatom_thumb_dir=='') {
		    $adultatom_thumb_dir = '../../feeds/';
	    }
	    if ($adultatom_thumb_url=='') {
		    $adultatom_thumb_url = get_option('siteurl') . '/wp-content/feeds/';
	    }
	    if (!($adultatom_post_author>0)) {
		    $adultatom_post_author = 1;
	    }
	    if (!($adultatom_post_category>0)) {
		    $adultatom_post_category = 0;
	    }
	    
	    if (!(count($adultatom_feeds)>0)) {
	    	$adultatom_feeds[0] = "http://www.cockcruisers.com/atom/packs/index.xml";
    	}
	    
	    if ($adultatom_css=='') {
		    $adultatom_css .= ".adultatom_flv_wrap { clear: both; padding: 3px; border: 0px solid #000000; }\n";
		    $adultatom_css .= ".adultatom_flv_text { width: 320px; clear: both; padding: 3px; border: 0px solid #000000; text-align: center; }\n";		    
		    $adultatom_css .= ".adultatom_mpeg_wrap { clear: both; width: 530px; border: 0px solid #000000; }\n";
		    $adultatom_css .= ".adultatom_mpeg { float: left; padding: 3px; border: 0px solid #000000; text-align: center; }\n";
		    $adultatom_css .= ".adultatom_link_wrap { clear: both; margin: 3px; border: 0px solid #000000; }\n";
		    $adultatom_css .= ".adultatom_link { font-size: large; font-weight: bold; padding: 3px; border: 0px solid #000000; }\n";
		    $adultatom_css .= ".adultatom_twotwofiveseven { clear: both; font-size: x-small; padding: 3px; border: 0px solid #000000; }\n";
		    $adultatom_css .= ".adultatom_other { font-size: x-small; padding: 3px; border: 0px solid #000000; }\n";
		    
	    }
    }
    
    echo '<div class="wrap">';
    echo "<h2>" . __( 'AdultATOM Plugin Options', 'mt_trans_domain' ) . "</h2>";
    ?>
	<form name="form1" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
	<input type="hidden" name="mt_submit_hidden" value="Y">

	<p><?php _e("Author ID:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_post_author" value="<?php echo $adultatom_post_author; ?>" size="3">
	</p>
	<p><?php _e("Category ID:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_post_category" value="<?php echo $adultatom_post_category; ?>" size="3">
	</p>	
	
	<p><?php _e("FLV Height:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_flash_height" value="<?php echo $adultatom_flash_height; ?>" size="4">
	</p>
	<p><?php _e("FLV Width:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_flash_width" value="<?php echo $adultatom_flash_width; ?>" size="4">
	</p>
	
	<p><?php _e("Thumb Height:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_thumb_height" value="<?php echo $adultatom_thumb_height; ?>" size="4">
	</p>
	<p><?php _e("Thumb Width:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_thumb_width" value="<?php echo $adultatom_thumb_width; ?>" size="4">
	</p>	
	
	<p><?php _e("Thumb Dir:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_thumb_dir" value="<?php echo $adultatom_thumb_dir; ?>" size="55">
	</p>
	<p><?php _e("Thumb URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_thumb_url" value="<?php echo $adultatom_thumb_url; ?>" size="55">
	</p>
	
	<p><?php _e("Include All Links:", 'mt_trans_domain' ); ?> 
	<?
	if ($adultatom_otherlinks==1) {
		$bChecked = "CHECKED";
	} else {
		$bChecked = "";
	}	
	 ?>
	<input type="checkbox" name="adultatom_otherlinks" value="1" <?=$bChecked?>> (Just 2257,FLVs,MPEGs or All?)
	</p>
	
	<p><?php _e("CSS:", 'mt_trans_domain' ); ?> 
	<TEXTAREA name="adultatom_css" ROWS=12 COLS=75><?php echo $adultatom_css; ?></TEXTAREA>
	</p>
	
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[0]" value="<?php echo $adultatom_feeds[0]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[1]" value="<?php echo $adultatom_feeds[1]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[2]" value="<?php echo $adultatom_feeds[2]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[3]" value="<?php echo $adultatom_feeds[3]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[4]" value="<?php echo $adultatom_feeds[4]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[5]" value="<?php echo $adultatom_feeds[5]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[6]" value="<?php echo $adultatom_feeds[6]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[7]" value="<?php echo $adultatom_feeds[7]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[8]" value="<?php echo $adultatom_feeds[8]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[9]" value="<?php echo $adultatom_feeds[9]; ?>" size="55">
	</p>
	<p><?php _e("Feed URL:", 'mt_trans_domain' ); ?> 
	<input type="text" name="adultatom_feeds[10]" value="<?php echo $adultatom_feeds[10]; ?>" size="55">
	</p>
	<hr />
	
	<p class="submit">
	<input type="submit" name="Submit" value="<?php _e('Update Options', 'mt_trans_domain' ) ?>" />
	</p>
	
	</form>
	</div>
<?
}





function sec2time($time){
	if(is_numeric($time)){
		$value = array(
			"years" => 0, "days" => 0, "hours" => 0,
			"minutes" => 0, "seconds" => 0,
		);
		if($time >= 31556926) {
			$value["years"] = floor($time/31556926);
			$time = ($time%31556926);
		}
		if($time >= 86400) {
			$value["days"] = floor($time/86400);
			$time = ($time%86400);
		}
		if($time >= 3600) {
			$value["hours"] = floor($time/3600);
			$time = ($time%3600);
		}
		if($time >= 60) {
			$value["minutes"] = floor($time/60);
			$time = ($time%60);
		}
		$value["seconds"] = floor($time);
		return (array) $value;
	} else {
		return (bool) FALSE;
	}
}

function SaveImage($type, $im, $filename, $quality, $to_file = true) {
	$res = null;
	if (!function_exists('imagegif')) $type = 3;
	switch ($type) {
		case 1:
			if ($to_file) {
				$res = ImageGIF($im, $filename);
			} else {
				header("Content-type: image/gif");
				$res = ImageGIF($im);
			}
			break;
		case 2:
			if ($to_file) {
				$res = ImageJPEG($im, $filename, $quality);
			} else {
				header("Content-type: image/jpeg");
				$res = ImageJPEG($im, '', $quality);
			}
			break;
		case 3:
			if ($to_file) {
				$res = ImagePNG($im, $filename);
			} else {
				header("Content-type: image/png");
				$res = ImagePNG($im, '', $quality);
			}
			break;
	}
	return $res;
}

function ImageCreateFromType($type, $filename) {
	$im = null;
	switch ($type) {
		case 1:
			$im = ImageCreateFromGif($filename);
			break;
		case 2:
			$im = ImageCreateFromJpeg($filename);
			break;
		case 3:
			$im = ImageCreateFromPNG($filename);
			break;
	}
	return $im;
}

function GenerateThumbFile($from_name, $to_name, $max_x, $max_y, $save_to_file, $image_type, $image_quality) {
	// get source image size (width/height/type)
	// orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
	list($orig_x, $orig_y, $orig_img_type, $img_sizes) = GetImageSize($from_name);
	// should we override thumb image type?
	$image_type = ($image_type != -1 ? $image_type : $orig_img_type);
	// check for allowed image types
	if ($orig_img_type < 1 or $orig_img_type > 3) die("Image type not supported");
	if ($orig_x > $max_x or $orig_y > $max_y) {
		// resize
		$per_x = $orig_x / $max_x;
		$per_y = $orig_y / $max_y;
		if ($per_y > $per_x) {
			$max_x = $orig_x / $per_y;
		} else {
			$max_y = $orig_y / $per_x;
		}
	} else {
		// keep original sizes, i.e. just copy
		if ($save_to_file) {
			@copy($from_name, $to_name);
		} else {
			switch ($image_type) {
				case 1:
					header("Content-type: image/gif");
					readfile($from_name);
					break;
				case 2:
					header("Content-type: image/jpeg");
					readfile($from_name);
					break;
				case 3:
					header("Content-type: image/png");
					readfile($from_name);
					break;
			}
		}
		return;
	}
	if ($image_type == 1) {
		// should use this function for gifs (gifs are palette images)
		$ni = imagecreate($max_x, $max_y);
	} else {
		// Create a new true color image
		$ni = ImageCreateTrueColor($max_x, $max_y);
	}
	// Fill image with white background (255,255,255)
	$white = imagecolorallocate($ni, 255, 255, 255);
	imagefilledrectangle($ni, 0, 0, $max_x, $max_y, $white);
	// Create a new image from source file
	$im = ImageCreateFromType($orig_img_type, $from_name);
	// Copy the palette from one image to another
	imagepalettecopy($ni, $im);
	// Copy and resize part of an image with resampling
	imagecopyresampled(
		$ni, $im, // destination, source
		0, 0, 0, 0, // dstX, dstY, srcX, srcY
		$max_x, $max_y, // dstW, dstH
		$orig_x, $orig_y); // srcW, srcH
	// save thumb file
	SaveImage($image_type, $ni, $to_name, $image_quality, $save_to_file);
	if ($temp) {
		unlink($tmpfname); // this removes the file
	}
}

?>
